<!DOCTYPE html>
<html lang="zh">
    <head><meta name="generator" content="Hexo 3.9.0">
    <!-- 
        © Material Theme
        https://github.com/viosey/hexo-theme-material
        Version: 1.3.0 -->

    <!-- Title -->
    
    <title>
        
            cas根据请求参数跳过验证 | 
        
        BirdZhang&#39;s Blog
    </title>

    <!-- Favicons -->
    <link rel="icon shortcut" type="image/ico" href="/img/favicon.png">
    <link rel="icon" sizes="192x192" href="/img/favicon.png">
    <link rel="apple-touch-icon" href="/img/favicon.png">

    <!-- Meta & Info -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="theme-color" content="#0097A7">
    <meta name="author" content="BirdZhang">
    <meta name="description" content="BirdZhang&#39;s GitHub pages powered by Hexo.io and hexo-theme-material.">
    <meta name="keywords" content="null,参数,cas,跳过">

    <!--iOS -->
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-title" content="Title">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="480">

    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">

    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="BirdZhang&#39;s Blog">

    <!-- The Open Graph protocol -->
    <meta property="og:url" content="http://birdzhang.xyz">
    <meta property="og:type" content="blog">
    <meta property="og:title" content="cas根据请求参数跳过验证 | BirdZhang&#39;s Blog">
    <meta property="og:description" content="BirdZhang&#39;s GitHub pages powered by Hexo.io and hexo-theme-material.">
    <meta property="og:article:tag" content="参数"> <meta property="og:article:tag" content="cas"> <meta property="og:article:tag" content="跳过"> 

    <!--[if lte IE 9]>
        <link rel="stylesheet" href="/css/ie-blocker.css">

        
            <script src="/js/ie-blocker.zhCN.js"></script>
        
    <![endif]-->

    <!-- Import CSS -->
    <link rel="stylesheet" href="/css/material.min.css">
    <link rel="stylesheet" href="/css/style.min.css">
    <!-- Config CSS -->


<!-- Other Styles -->
<style>
  body, html {
    font-family: Roboto, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  }

  a {
    color: #00838F;
  }

  .mdl-card__media,
  #search-label,
  #search-form-label:after,
  #scheme-Paradox .hot_tags-count,
  #scheme-Paradox .sidebar_archives-count,
  #scheme-Paradox .sidebar-colored .sidebar-header,
  #scheme-Paradox .sidebar-colored .sidebar-badge{
    background-color: #0097A7 !important;
  }

  /* Sidebar User Drop Down Menu Text Color */
  #scheme-Paradox .sidebar-colored .sidebar-nav>.dropdown>.dropdown-menu>li>a:hover,
  #scheme-Paradox .sidebar-colored .sidebar-nav>.dropdown>.dropdown-menu>li>a:focus {
    color: #0097A7 !important;
  }

  #post_entry-right-info,
  .sidebar-colored .sidebar-nav li:hover > a,
  .sidebar-colored .sidebar-nav li:hover > a i,
  .sidebar-colored .sidebar-nav li > a:hover,
  .sidebar-colored .sidebar-nav li > a:hover i,
  .sidebar-colored .sidebar-nav li > a:focus i,
  .sidebar-colored .sidebar-nav > .open > a,
  .sidebar-colored .sidebar-nav > .open > a:hover,
  .sidebar-colored .sidebar-nav > .open > a:focus,
  #ds-reset #ds-ctx .ds-ctx-entry .ds-ctx-head a {
    color: #0097A7 !important;
  }

  .toTop {
    background: #757575 !important;
  }

  .material-layout .material-post>.material-nav,
  .material-layout .material-index>.material-nav,
  .material-nav a {
    color: #757575;
  }

  #scheme-Paradox .MD-burger-layer {
    background-color: #757575;
  }

  #scheme-Paradox #post-toc-trigger-btn {
    color: #757575;
  }

  .post-toc a:hover {
    color: #00838F;
    text-decoration: underline;
  }
</style>


<!-- Theme Background Related-->

    <style>
      body{
        background-color: #F5F5F5;
      }

      /* blog_info bottom background */
      #scheme-Paradox .material-layout .something-else .mdl-card__supporting-text{
        background-color: #fff;
      }
    </style>




<!-- Fade Effect -->

    <style>
      .fade {
        transition: all 800ms linear;
        -webkit-transform: translate3d(0,0,0);
        -moz-transform: translate3d(0,0,0);
        -ms-transform: translate3d(0,0,0);
        -o-transform: translate3d(0,0,0);
        transform: translate3d(0,0,0);
        opacity: 1;
      }

      .fade.out{
        opacity: 0;
      }
    </style>



    <script src="/js/jquery.min.js"></script>
    <script src="/js/queue.js"></script>

    <!-- UC Browser Compatible -->
    <script>
        var agent = navigator.userAgent.toLowerCase();
        if(agent.indexOf('ucbrowser')>0) {
            document.write("<link rel=\"stylesheet\" href=\"/css/uc.css\">");
            alert('由于 UC 浏览器使用极旧的内核，而本网站使用了一些新的特性。\n为了您能更好的浏览，推荐使用 Chrome 或 Firefox 浏览器。');
        }
    </script>

    

    

    <!-- Bing Background -->
    

    <!-- Custom Head -->
    
</head>


    
        <body id="scheme-Paradox" class="lazy">
            <div class="material-layout  mdl-js-layout has-drawer is-upgraded">
                

                <!-- Main Container -->
                <main class="material-layout__content" id="main">

                    <!-- Top Anchor -->
                    <div id="top"></div>

                    
                        <!-- Hamburger Button -->
                        <button class="MD-burger-icon sidebar-toggle">
                            <span class="MD-burger-layer"></span>
                        </button>
                    

                    <!-- Post TOC -->

    
    <!-- Back Button -->
    <!--
    <div class="material-back" id="backhome-div" tabindex="0">
        <a class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon"
           href="#" onclick="window.history.back();return false;"
           target="_self"
           role="button"
           data-upgraded=",MaterialButton,MaterialRipple">
            <i class="material-icons" role="presentation">arrow_back</i>
            <span class="mdl-button__ripple-container">
                <span class="mdl-ripple"></span>
            </span>
        </a>
    </div>
    -->

    <!-- Left aligned menu below button -->
    <button id="post-toc-trigger-btn"
        class="mdl-button mdl-js-button mdl-button--icon">
        <i class="material-icons">format_list_numbered</i>
    </button>

    <ul class="post-toc-wrap mdl-menu mdl-menu--bottom-left mdl-js-menu mdl-js-ripple-effect" for="post-toc-trigger-btn">
        <ol class="post-toc"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#CAS-Authentication-Filter-代码"><span class="post-toc-number">1.</span> <span class="post-toc-text">CAS Authentication Filter 代码</span></a></li></ol>

        <!--
        <li class="mdl-menu__item">
            Some Action
        </li>
        -->
    </ul>




<!-- Layouts -->

    <!-- Post Module -->
    <div class="material-post_container">

        <div class="material-post mdl-grid">
            <div class="mdl-card mdl-shadow--4dp mdl-cell mdl-cell--12-col">

                <!-- Post Header(Thumbnail & Title) -->
                
    <!-- Paradox Post Header -->
    
        
            <!-- Random Thumbnail -->
            <div class="post_thumbnail-random mdl-card__media mdl-color-text--grey-50">
            <script>
    var randomNum = Math.floor(Math.random() * 19 + 1);

    $('.post_thumbnail-random').css('background-image', 'url(' + '/img/random/material-' + randomNum + '.png' + ')');
</script>

        
    
            <p class="article-headline-p">
                cas根据请求参数跳过验证
            </p>
        </div>





                
                    <!-- Paradox Post Info -->
                    <div class="mdl-color-text--grey-700 mdl-card__supporting-text meta">

    <!-- Author Avatar -->
    <div id="author-avatar">
        <img src="/img/avatar.png" width="44px" height="44px" alt="Author Avatar"/>
    </div>
    <!-- Author Name & Date -->
    <div>
        <strong>BirdZhang</strong>
        <span>5月 15, 2018</span>
    </div>

    <div class="section-spacer"></div>

    <!-- Favorite -->
    <!--
        <button id="article-functions-like-button" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon btn-like">
            <i class="material-icons" role="presentation">favorite</i>
            <span class="visuallyhidden">favorites</span>
        </button>
    -->

    <!-- Qrcode -->
    

    <!-- Tags (bookmark) -->
    
    <button id="article-functions-viewtags-button" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
        <i class="material-icons" role="presentation">bookmark</i>
        <span class="visuallyhidden">bookmark</span>
    </button>
    <ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="article-functions-viewtags-button">
        <li class="mdl-menu__item">
        <a class="post_tag-link" href="/tags/cas/">cas</a></li><li class="mdl-menu__item"><a class="post_tag-link" href="/tags/参数/">参数</a></li><li class="mdl-menu__item"><a class="post_tag-link" href="/tags/跳过/">跳过</a>
    </ul>
    

    <!-- Share -->
    <button id="article-fuctions-share-button" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
    <i class="material-icons" role="presentation">share</i>
    <span class="visuallyhidden">share</span>
</button>
<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="article-fuctions-share-button">
    
    <!-- Leancloud Views -->
        <a class="post_share-link" href="#">
            <li class="mdl-menu__item">
                <span id="/2018/05/15/cas根据请求参数跳过验证/" class="leancloud-views_num" data-flag-title="cas根据请求参数跳过验证">
     &nbsp;浏览量
</span>

            </li>
        </a>
    

    

    <!-- Share Weibo -->
    
        <a class="post_share-link" href="http://service.weibo.com/share/share.php?appkey=&title=cas根据请求参数跳过验证&url=http://birdzhang.xyz//2018/05/15/cas根据请求参数跳过验证/index.html&pic=&searchPic=false&style=simple" target="_blank">
            <li class="mdl-menu__item">
                分享到微博
            </li>
        </a>
    

    <!-- Share Twitter -->
    
        <a class="post_share-link" href="https://twitter.com/intent/tweet?text=cas根据请求参数跳过验证&url=http://birdzhang.xyz//2018/05/15/cas根据请求参数跳过验证/index.html&via=BirdZhang" target="_blank">
            <li class="mdl-menu__item">
                分享到 Twitter
            </li>
        </a>
    

    <!-- Share Facebook -->
    
        <a class="post_share-link" href="https://www.facebook.com/sharer/sharer.php?u=http://birdzhang.xyz//2018/05/15/cas根据请求参数跳过验证/index.html" target="_blank">
            <li class="mdl-menu__item">
                分享到 Facebook
            </li>
        </a>
    

    <!-- Share Google+ -->
    
        <a class="post_share-link" href="https://plus.google.com/share?url=http://birdzhang.xyz//2018/05/15/cas根据请求参数跳过验证/index.html" target="_blank">
            <li class="mdl-menu__item">
                分享到 Google+
            </li>
        </a>
    

    <!-- Share LinkedIn -->
    

    <!-- Share QQ -->
    

    <!-- Share Telegram -->
    
</ul>

</div>

                

                <!-- Post Content -->
                <div id="post-content" class="mdl-color-text--grey-700 mdl-card__supporting-text fade out">
    
        <p>接上一篇 <a href="https://birdzhang.xyz/2018/05/15/Java%E6%94%B9%E5%86%99HttpServletRequest%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0/">https://birdzhang.xyz/2018/05/15/Java%E6%94%B9%E5%86%99HttpServletRequest%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0/</a> ，这里说一下cas的坑（这里的cas是3.5版本）</p>
<p>虽然cas有CAS Authentication Filter，但是这个只是根据请求的uri过滤的，那么这里就出现了一个奇怪的bug</p>
<p>即使我在<code>excludePaths</code>里面添加了<code>/test1/</code>，但是当请求地址为<code>/test1/123?ticket=123</code>的时候，还是会去cas服务器验证！！！</p>
<p>我们来看代码：</p>
<h5 id="CAS-Authentication-Filter-代码"><a href="#CAS-Authentication-Filter-代码" class="headerlink" title="CAS Authentication Filter 代码"></a>CAS Authentication Filter 代码</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.birdzhang.demo.check;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.FilterChain;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.FilterConfig;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.ServletException;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.ServletRequest;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.ServletResponse;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletRequest;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletResponse;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpSession;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.jasig.cas.client.authentication.DefaultGatewayResolverImpl;</span><br><span class="line"><span class="keyword">import</span> org.jasig.cas.client.authentication.GatewayResolver;</span><br><span class="line"><span class="keyword">import</span> org.jasig.cas.client.util.AbstractCasFilter;</span><br><span class="line"><span class="keyword">import</span> org.jasig.cas.client.util.CommonUtils;</span><br><span class="line"><span class="keyword">import</span> org.jasig.cas.client.validation.Assertion;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AuthenticationFilter</span> <span class="keyword">extends</span> <span class="title">AbstractCasFilter</span></span>&#123;</span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line">	 <span class="comment">/**</span></span><br><span class="line"><span class="comment">    * The URL to the CAS Server login.</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">   <span class="keyword">private</span> String casServerLoginUrl;</span><br><span class="line"></span><br><span class="line">   <span class="comment">/**</span></span><br><span class="line"><span class="comment">    * Whether to send the renew request or not.</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">   <span class="keyword">private</span> <span class="keyword">boolean</span> renew = <span class="keyword">false</span>;</span><br><span class="line"></span><br><span class="line">   <span class="comment">/**</span></span><br><span class="line"><span class="comment">    * Whether to send the gateway request or not.</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">   <span class="keyword">private</span> <span class="keyword">boolean</span> gateway = <span class="keyword">false</span>;</span><br><span class="line">   <span class="comment">/**</span></span><br><span class="line"><span class="comment">    * 添加属性，这里用来存放不过滤地址正则表达式，可以根据自己需求定制---1</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">   <span class="keyword">private</span> String excludePaths;</span><br><span class="line">   </span><br><span class="line">   <span class="keyword">private</span> GatewayResolver gatewayStorage = <span class="keyword">new</span> DefaultGatewayResolverImpl();</span><br><span class="line"></span><br><span class="line">   <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">initInternal</span><span class="params">(<span class="keyword">final</span> FilterConfig filterConfig)</span> <span class="keyword">throws</span> ServletException </span>&#123;</span><br><span class="line">       <span class="keyword">if</span> (!isIgnoreInitConfiguration()) &#123;</span><br><span class="line">           <span class="keyword">super</span>.initInternal(filterConfig);</span><br><span class="line">           setCasServerLoginUrl(getPropertyFromInitParams(filterConfig, <span class="string">"casServerLoginUrl"</span>, <span class="keyword">null</span>));</span><br><span class="line">           <span class="comment">//log.trace("Loaded CasServerLoginUrl parameter: " + this.casServerLoginUrl);</span></span><br><span class="line">           setRenew(parseBoolean(getPropertyFromInitParams(filterConfig, <span class="string">"renew"</span>, <span class="string">"false"</span>)));</span><br><span class="line">           <span class="comment">//log.trace("Loaded renew parameter: " + this.renew);</span></span><br><span class="line">           setGateway(parseBoolean(getPropertyFromInitParams(filterConfig, <span class="string">"gateway"</span>, <span class="string">"false"</span>)));</span><br><span class="line">           <span class="comment">//log.trace("Loaded gateway parameter: " + this.gateway);</span></span><br><span class="line"></span><br><span class="line">           <span class="keyword">final</span> String gatewayStorageClass = getPropertyFromInitParams(filterConfig, <span class="string">"gatewayStorageClass"</span>, <span class="keyword">null</span>);</span><br><span class="line"></span><br><span class="line">           <span class="keyword">if</span> (gatewayStorageClass != <span class="keyword">null</span>) &#123;</span><br><span class="line">               <span class="keyword">try</span> &#123;</span><br><span class="line">                   <span class="keyword">this</span>.gatewayStorage = (GatewayResolver) Class.forName(gatewayStorageClass).newInstance();</span><br><span class="line">               &#125; <span class="keyword">catch</span> (<span class="keyword">final</span> Exception e) &#123;</span><br><span class="line">                   <span class="comment">//log.error(e,e);</span></span><br><span class="line">                   <span class="keyword">throw</span> <span class="keyword">new</span> ServletException(e);</span><br><span class="line">               &#125;</span><br><span class="line">           &#125;</span><br><span class="line">           <span class="comment">//自定义添加代码，用来读取web配置文件中excludes属性值 ---2</span></span><br><span class="line">           excludePaths = getPropertyFromInitParams(filterConfig, <span class="string">"excludePaths"</span>, <span class="keyword">null</span>);<span class="comment">//filterConfig.getInitParameter("excludePaths");</span></span><br><span class="line">           excludePaths = excludePaths.trim();</span><br><span class="line">       &#125;</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">init</span><span class="params">()</span> </span>&#123;</span><br><span class="line">       <span class="keyword">super</span>.init();</span><br><span class="line">       CommonUtils.assertNotNull(<span class="keyword">this</span>.casServerLoginUrl, <span class="string">"casServerLoginUrl cannot be null."</span>);</span><br><span class="line">   &#125;</span><br><span class="line"><span class="comment">//url判断逻辑，这里大家可以根据自己需要来制订规则</span></span><br><span class="line">   <span class="function"><span class="keyword">private</span> <span class="keyword">boolean</span> <span class="title">isExclude</span><span class="params">(String uri)</span></span>&#123;</span><br><span class="line">   	<span class="keyword">boolean</span> isInWhiteList = <span class="keyword">false</span>;</span><br><span class="line">   	<span class="keyword">if</span>(excludePaths!=<span class="keyword">null</span>&amp;&amp; uri!=<span class="keyword">null</span>)&#123;</span><br><span class="line">   		isInWhiteList = uri.matches(excludePaths);</span><br><span class="line">   	&#125;</span><br><span class="line">       <span class="keyword">return</span> isInWhiteList;</span><br><span class="line">   &#125;</span><br><span class="line">  </span><br><span class="line">   </span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">doFilter</span><span class="params">(<span class="keyword">final</span> ServletRequest servletRequest, <span class="keyword">final</span> ServletResponse servletResponse, <span class="keyword">final</span> FilterChain filterChain)</span> <span class="keyword">throws</span> IOException, ServletException </span>&#123;</span><br><span class="line">       <span class="keyword">final</span> HttpServletRequest request = (HttpServletRequest) servletRequest;</span><br><span class="line">       <span class="keyword">final</span> HttpServletResponse response = (HttpServletResponse) servletResponse;</span><br><span class="line">       <span class="keyword">final</span> HttpSession session = request.getSession(<span class="keyword">false</span>);</span><br><span class="line">       <span class="keyword">final</span> Assertion assertion = session != <span class="keyword">null</span> ? (Assertion) session.getAttribute(CONST_CAS_ASSERTION) : <span class="keyword">null</span>;</span><br><span class="line">      <span class="comment">// 该判断是自定义的对符合条件的url进行通过处理 ---3</span></span><br><span class="line">       <span class="keyword">if</span>(isExclude(request.getRequestURI()))&#123;</span><br><span class="line">       	filterChain.doFilter(request, response);</span><br><span class="line">           <span class="keyword">return</span>;</span><br><span class="line">       &#125;</span><br><span class="line">       </span><br><span class="line">       <span class="keyword">if</span> (assertion != <span class="keyword">null</span>) &#123;</span><br><span class="line">           filterChain.doFilter(request, response);</span><br><span class="line">           <span class="keyword">return</span>;</span><br><span class="line">       &#125;</span><br><span class="line"></span><br><span class="line">       <span class="keyword">final</span> String serviceUrl = constructServiceUrl(request, response);</span><br><span class="line">       <span class="keyword">final</span> String ticket = CommonUtils.safeGetParameter(request,getArtifactParameterName());</span><br><span class="line">       <span class="keyword">final</span> <span class="keyword">boolean</span> wasGatewayed = <span class="keyword">this</span>.gatewayStorage.hasGatewayedAlready(request, serviceUrl);</span><br><span class="line"></span><br><span class="line">       <span class="keyword">if</span> (CommonUtils.isNotBlank(ticket) || wasGatewayed) &#123;</span><br><span class="line">           filterChain.doFilter(request, response);</span><br><span class="line">           <span class="keyword">return</span>;</span><br><span class="line">       &#125;</span><br><span class="line"></span><br><span class="line">       <span class="keyword">final</span> String modifiedServiceUrl;</span><br><span class="line"></span><br><span class="line">       <span class="comment">//log.debug("no ticket and no assertion found");</span></span><br><span class="line">       <span class="keyword">if</span> (<span class="keyword">this</span>.gateway) &#123;</span><br><span class="line">           <span class="comment">//log.debug("setting gateway attribute in session");</span></span><br><span class="line">           modifiedServiceUrl = <span class="keyword">this</span>.gatewayStorage.storeGatewayInformation(request, serviceUrl);</span><br><span class="line">       &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">           modifiedServiceUrl = serviceUrl;</span><br><span class="line">       &#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*       if (log.isDebugEnabled()) &#123;</span></span><br><span class="line"><span class="comment">           log.debug("Constructed service url: " + modifiedServiceUrl);</span></span><br><span class="line"><span class="comment">       &#125;*/</span></span><br><span class="line"></span><br><span class="line">       <span class="keyword">final</span> String urlToRedirectTo = CommonUtils.constructRedirectUrl(<span class="keyword">this</span>.casServerLoginUrl, getServiceParameterName(), modifiedServiceUrl, <span class="keyword">this</span>.renew, <span class="keyword">this</span>.gateway);</span><br><span class="line"></span><br><span class="line">  <span class="comment">/*     if (log.isDebugEnabled()) &#123;</span></span><br><span class="line"><span class="comment">           log.debug("redirecting to \"" + urlToRedirectTo + "\"");</span></span><br><span class="line"><span class="comment">       &#125;*/</span></span><br><span class="line"></span><br><span class="line">       response.sendRedirect(urlToRedirectTo);</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">setRenew</span><span class="params">(<span class="keyword">final</span> <span class="keyword">boolean</span> renew)</span> </span>&#123;</span><br><span class="line">       <span class="keyword">this</span>.renew = renew;</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">setGateway</span><span class="params">(<span class="keyword">final</span> <span class="keyword">boolean</span> gateway)</span> </span>&#123;</span><br><span class="line">       <span class="keyword">this</span>.gateway = gateway;</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">setCasServerLoginUrl</span><span class="params">(<span class="keyword">final</span> String casServerLoginUrl)</span> </span>&#123;</span><br><span class="line">       <span class="keyword">this</span>.casServerLoginUrl = casServerLoginUrl;</span><br><span class="line">   &#125;</span><br><span class="line">   </span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">setGatewayStorage</span><span class="params">(<span class="keyword">final</span> GatewayResolver gatewayStorage)</span> </span>&#123;</span><br><span class="line">   	<span class="keyword">this</span>.gatewayStorage = gatewayStorage;</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>可以看到在uri匹配到excludepath之后会走<code>filterChain.doFilter(request, response);</code>，由于我们并没有对filterChain做什么修改，所以最终还是跑到cas那里去了</p>
<p>修改后的代码如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.birdzhang.plugin;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> debo.zhang</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.FilterChain;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.FilterConfig;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.ServletException;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.ServletRequest;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.ServletResponse;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletRequest;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletResponse;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpSession;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.jasig.cas.client.authentication.DefaultGatewayResolverImpl;</span><br><span class="line"><span class="keyword">import</span> org.jasig.cas.client.authentication.GatewayResolver;</span><br><span class="line"><span class="keyword">import</span> org.jasig.cas.client.util.AbstractCasFilter;</span><br><span class="line"><span class="keyword">import</span> org.jasig.cas.client.util.CommonUtils;</span><br><span class="line"><span class="keyword">import</span> org.jasig.cas.client.validation.Assertion;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AuthenticationFilter</span> <span class="keyword">extends</span> <span class="title">AbstractCasFilter</span></span>&#123;</span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line">	 <span class="comment">/**</span></span><br><span class="line"><span class="comment">    * The URL to the CAS Server login.</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">   <span class="keyword">private</span> String casServerLoginUrl;</span><br><span class="line"></span><br><span class="line">   <span class="comment">/**</span></span><br><span class="line"><span class="comment">    * Whether to send the renew request or not.</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">   <span class="keyword">private</span> <span class="keyword">boolean</span> renew = <span class="keyword">false</span>;</span><br><span class="line"></span><br><span class="line">   <span class="comment">/**</span></span><br><span class="line"><span class="comment">    * Whether to send the gateway request or not.</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">   <span class="keyword">private</span> <span class="keyword">boolean</span> gateway = <span class="keyword">false</span>;</span><br><span class="line">   <span class="comment">/**</span></span><br><span class="line"><span class="comment">    * 添加属性，这里用来存放不过滤地址正则表达式，可以根据自己需求定制---1</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">   <span class="keyword">private</span> String excludePaths;</span><br><span class="line">   </span><br><span class="line">   <span class="keyword">private</span> GatewayResolver gatewayStorage = <span class="keyword">new</span> DefaultGatewayResolverImpl();</span><br><span class="line"></span><br><span class="line">   <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">initInternal</span><span class="params">(<span class="keyword">final</span> FilterConfig filterConfig)</span> <span class="keyword">throws</span> ServletException </span>&#123;</span><br><span class="line">       <span class="keyword">if</span> (!isIgnoreInitConfiguration()) &#123;</span><br><span class="line">           <span class="keyword">super</span>.initInternal(filterConfig);</span><br><span class="line">           setCasServerLoginUrl(getPropertyFromInitParams(filterConfig, <span class="string">"casServerLoginUrl"</span>, <span class="keyword">null</span>));</span><br><span class="line">           <span class="comment">//log.trace("Loaded CasServerLoginUrl parameter: " + this.casServerLoginUrl);</span></span><br><span class="line">           setRenew(parseBoolean(getPropertyFromInitParams(filterConfig, <span class="string">"renew"</span>, <span class="string">"false"</span>)));</span><br><span class="line">           <span class="comment">//log.trace("Loaded renew parameter: " + this.renew);</span></span><br><span class="line">           setGateway(parseBoolean(getPropertyFromInitParams(filterConfig, <span class="string">"gateway"</span>, <span class="string">"false"</span>)));</span><br><span class="line">           <span class="comment">//log.trace("Loaded gateway parameter: " + this.gateway);</span></span><br><span class="line"></span><br><span class="line">           <span class="keyword">final</span> String gatewayStorageClass = getPropertyFromInitParams(filterConfig, <span class="string">"gatewayStorageClass"</span>, <span class="keyword">null</span>);</span><br><span class="line"></span><br><span class="line">           <span class="keyword">if</span> (gatewayStorageClass != <span class="keyword">null</span>) &#123;</span><br><span class="line">               <span class="keyword">try</span> &#123;</span><br><span class="line">                   <span class="keyword">this</span>.gatewayStorage = (GatewayResolver) Class.forName(gatewayStorageClass).newInstance();</span><br><span class="line">               &#125; <span class="keyword">catch</span> (<span class="keyword">final</span> Exception e) &#123;</span><br><span class="line">                   <span class="comment">//log.error(e,e);</span></span><br><span class="line">                   <span class="keyword">throw</span> <span class="keyword">new</span> ServletException(e);</span><br><span class="line">               &#125;</span><br><span class="line">           &#125;</span><br><span class="line">           <span class="comment">//自定义添加代码，用来读取web配置文件中excludes属性值 ---2</span></span><br><span class="line">           excludePaths = getPropertyFromInitParams(filterConfig, <span class="string">"excludePaths"</span>, <span class="keyword">null</span>);<span class="comment">//filterConfig.getInitParameter("excludePaths");</span></span><br><span class="line">           excludePaths = excludePaths.trim();</span><br><span class="line">       &#125;</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">init</span><span class="params">()</span> </span>&#123;</span><br><span class="line">       <span class="keyword">super</span>.init();</span><br><span class="line">       CommonUtils.assertNotNull(<span class="keyword">this</span>.casServerLoginUrl, <span class="string">"casServerLoginUrl cannot be null."</span>);</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   <span class="comment">//url判断逻辑，这里大家可以根据自己需要来制订规则</span></span><br><span class="line">   <span class="function"><span class="keyword">private</span> <span class="keyword">boolean</span> <span class="title">isExclude</span><span class="params">(String uri)</span></span>&#123;</span><br><span class="line">   	<span class="keyword">boolean</span> isInWhiteList = <span class="keyword">false</span>;</span><br><span class="line">   	<span class="keyword">if</span>(excludePaths!=<span class="keyword">null</span>&amp;&amp; uri!=<span class="keyword">null</span>)&#123;</span><br><span class="line">   		isInWhiteList = uri.matches(excludePaths);</span><br><span class="line">   	&#125;</span><br><span class="line">       <span class="keyword">return</span> isInWhiteList;</span><br><span class="line">   &#125;</span><br><span class="line">  </span><br><span class="line">   </span><br><span class="line">   </span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">doFilter</span><span class="params">(<span class="keyword">final</span> ServletRequest servletRequest, <span class="keyword">final</span> ServletResponse servletResponse, <span class="keyword">final</span> FilterChain filterChain)</span> <span class="keyword">throws</span> IOException, ServletException </span>&#123;</span><br><span class="line">       HttpServletRequest request = (HttpServletRequest) servletRequest;</span><br><span class="line">       <span class="keyword">final</span> HttpServletResponse response = (HttpServletResponse) servletResponse;</span><br><span class="line">       <span class="keyword">final</span> HttpSession session = request.getSession(<span class="keyword">false</span>);</span><br><span class="line">       </span><br><span class="line">       <span class="keyword">final</span> Assertion assertion = session != <span class="keyword">null</span> ? (Assertion) session.getAttribute(CONST_CAS_ASSERTION) : <span class="keyword">null</span>;</span><br><span class="line"></span><br><span class="line">       <span class="comment">//hack for 云桥</span></span><br><span class="line">       Map&lt;String, String[]&gt;	paramsMap = request.getParameterMap();</span><br><span class="line">       </span><br><span class="line">       <span class="keyword">if</span>(<span class="keyword">null</span> != paramsMap ) &#123;</span><br><span class="line">    	   <span class="keyword">if</span>(paramsMap.containsKey(<span class="string">"ticket"</span>) &amp;&amp; paramsMap.containsKey(<span class="string">"operation"</span>)) &#123;</span><br><span class="line"><span class="comment">/*    		   String token = Arrays.toString(paramsMap.get("ticket"));</span></span><br><span class="line"><span class="comment">    		   request.removeAttribute("ticket");</span></span><br><span class="line"><span class="comment">    		   request.setAttribute("token", token.substring(1, token.length()-1));</span></span><br><span class="line"><span class="comment">    		   filterChain.doFilter(request, response);</span></span><br><span class="line"><span class="comment">               return;*/</span></span><br><span class="line">               </span><br><span class="line">    		   <span class="comment">/*StringBuffer paramsBuff = new StringBuffer();</span></span><br><span class="line"><span class="comment">    	       for(String param: paramsMap.keySet()) &#123;</span></span><br><span class="line"><span class="comment">    	    	   String newString = Arrays.toString(paramsMap.get(param));</span></span><br><span class="line"><span class="comment">    	    	   if(param.equals("ticket")) &#123;</span></span><br><span class="line"><span class="comment">    	    		   paramsBuff.append("&amp;").append("eticket").append("=").append(newString.substring(1, newString.length()-1));</span></span><br><span class="line"><span class="comment">    	    	   &#125;else &#123;</span></span><br><span class="line"><span class="comment">    	    		   paramsBuff.append("&amp;").append(param).append("=").append(newString.substring(1, newString.length()-1));</span></span><br><span class="line"><span class="comment">    	    	   &#125;</span></span><br><span class="line"><span class="comment">    	       &#125;</span></span><br><span class="line"><span class="comment">    	       String port = request.getServerPort() == 80?"":":"+request.getServerPort();</span></span><br><span class="line"><span class="comment">    	       String scheme = request.getScheme();</span></span><br><span class="line"><span class="comment">    	       String host = request.getServerName();</span></span><br><span class="line"><span class="comment">    	       String redirectUrl = String.format("%s://%s%s%s?%s", </span></span><br><span class="line"><span class="comment">    	    		   scheme,</span></span><br><span class="line"><span class="comment">    	    		   host,</span></span><br><span class="line"><span class="comment">    	    		   port,</span></span><br><span class="line"><span class="comment">    	    		   request.getRequestURI(),</span></span><br><span class="line"><span class="comment">    	    		   paramsBuff.toString().substring(1)</span></span><br><span class="line"><span class="comment">    	    		   );</span></span><br><span class="line"><span class="comment">    	       System.out.println("request url:"+redirectUrl);</span></span><br><span class="line"><span class="comment">    	       response.sendRedirect(redirectUrl);</span></span><br><span class="line"><span class="comment">    	       return;*/</span></span><br><span class="line">    		   </span><br><span class="line">    		   Map&lt;String, String[]&gt; extraParams = <span class="keyword">new</span> HashMap&lt;String, String[]&gt;();</span><br><span class="line">    		   HttpServletRequest wrappedRequest = <span class="keyword">new</span> PrettyFacesWrappedRequest(request, extraParams);</span><br><span class="line">    		   request.getRequestDispatcher(request.getRequestURI()).forward(wrappedRequest, response);</span><br><span class="line">    		   <span class="keyword">return</span>;</span><br><span class="line">    	   &#125;</span><br><span class="line">       &#125;</span><br><span class="line">       </span><br><span class="line">       </span><br><span class="line">       <span class="comment">// 该判断是自定义的对符合条件的url进行通过处理 </span></span><br><span class="line">       <span class="keyword">if</span>(isExclude(request.getRequestURI()))&#123;</span><br><span class="line">       	filterChain.doFilter(request, response);</span><br><span class="line">           <span class="keyword">return</span>;</span><br><span class="line">       &#125;</span><br><span class="line">       </span><br><span class="line">      </span><br><span class="line">       </span><br><span class="line">       <span class="keyword">if</span> (assertion != <span class="keyword">null</span>) &#123;</span><br><span class="line">           filterChain.doFilter(request, response);</span><br><span class="line">           <span class="keyword">return</span>;</span><br><span class="line">       &#125;</span><br><span class="line"></span><br><span class="line">       <span class="keyword">final</span> String serviceUrl = constructServiceUrl(request, response);</span><br><span class="line">       <span class="keyword">final</span> String ticket = CommonUtils.safeGetParameter(request,getArtifactParameterName());</span><br><span class="line">       <span class="keyword">final</span> <span class="keyword">boolean</span> wasGatewayed = <span class="keyword">this</span>.gatewayStorage.hasGatewayedAlready(request, serviceUrl);</span><br><span class="line"></span><br><span class="line">       <span class="keyword">if</span> (CommonUtils.isNotBlank(ticket) || wasGatewayed) &#123;</span><br><span class="line">           filterChain.doFilter(request, response);</span><br><span class="line">           <span class="keyword">return</span>;</span><br><span class="line">       &#125;</span><br><span class="line"></span><br><span class="line">       <span class="keyword">final</span> String modifiedServiceUrl;</span><br><span class="line"></span><br><span class="line">       <span class="comment">//log.debug("no ticket and no assertion found");</span></span><br><span class="line">       <span class="keyword">if</span> (<span class="keyword">this</span>.gateway) &#123;</span><br><span class="line">           <span class="comment">//log.debug("setting gateway attribute in session");</span></span><br><span class="line">           modifiedServiceUrl = <span class="keyword">this</span>.gatewayStorage.storeGatewayInformation(request, serviceUrl);</span><br><span class="line">       &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">           modifiedServiceUrl = serviceUrl;</span><br><span class="line">       &#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*       if (log.isDebugEnabled()) &#123;</span></span><br><span class="line"><span class="comment">           log.debug("Constructed service url: " + modifiedServiceUrl);</span></span><br><span class="line"><span class="comment">       &#125;*/</span></span><br><span class="line"></span><br><span class="line">       <span class="keyword">final</span> String urlToRedirectTo = CommonUtils.constructRedirectUrl(<span class="keyword">this</span>.casServerLoginUrl, getServiceParameterName(), modifiedServiceUrl, <span class="keyword">this</span>.renew, <span class="keyword">this</span>.gateway);</span><br><span class="line"></span><br><span class="line">  <span class="comment">/*     if (log.isDebugEnabled()) &#123;</span></span><br><span class="line"><span class="comment">           log.debug("redirecting to \"" + urlToRedirectTo + "\"");</span></span><br><span class="line"><span class="comment">       &#125;*/</span></span><br><span class="line"></span><br><span class="line">       response.sendRedirect(urlToRedirectTo);</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">setRenew</span><span class="params">(<span class="keyword">final</span> <span class="keyword">boolean</span> renew)</span> </span>&#123;</span><br><span class="line">       <span class="keyword">this</span>.renew = renew;</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">setGateway</span><span class="params">(<span class="keyword">final</span> <span class="keyword">boolean</span> gateway)</span> </span>&#123;</span><br><span class="line">       <span class="keyword">this</span>.gateway = gateway;</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">setCasServerLoginUrl</span><span class="params">(<span class="keyword">final</span> String casServerLoginUrl)</span> </span>&#123;</span><br><span class="line">       <span class="keyword">this</span>.casServerLoginUrl = casServerLoginUrl;</span><br><span class="line">   &#125;</span><br><span class="line">   </span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">setGatewayStorage</span><span class="params">(<span class="keyword">final</span> GatewayResolver gatewayStorage)</span> </span>&#123;</span><br><span class="line">   	<span class="keyword">this</span>.gatewayStorage = gatewayStorage;</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
    

    
</div>


                

                <!-- Post Comments -->
                
                    


    <!-- 使用 DISQUS -->
    <div id="disqus-comment">
        <div id="disqus_thread"></div>
<script>
    queue.offer(function() {
            var disqus_config = function () {
                this.page.url = 'http://birdzhang.xyz/2018/05/15/cas根据请求参数跳过验证/index.html';  // Replace PAGE_URL with your page's canonical URL variable
                this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
            };

            (function() { // DON'T EDIT BELOW THIS LINE
                var d = document;
                var s = d.createElement('script');
                s.src = '//0312birdzhang-github-io.disqus.com/embed.js';
                s.setAttribute('data-timestamp', + new Date());
                (d.head || d.body).appendChild(s);
            })();
        });
</script>

    </div>
    <style>
        #disqus-comment{
            background-color: #eee;
            padding: 2pc;
        }
    </style>



                
            </div>

            <!-- Post Prev & Next Nav -->
            <nav class="material-nav mdl-color-text--grey-50 mdl-cell mdl-cell--12-col">
    <!-- Prev Nav -->
    
        <a href="/2018/06/05/使用openresty搭一个类似ip-cn的接口/" id="post_nav-newer" class="prev-content">
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation">
                <i class="material-icons">arrow_back</i>
            </button>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            新篇
        </a>
    

    <!-- Section Spacer -->
    <div class="section-spacer"></div>

    <!-- Next Nav -->
    
        <a href="/2018/05/15/Java改写HttpServletRequest请求参数/" id="post_nav-older" class="next-content">
            旧篇
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation">
                <i class="material-icons">arrow_forward</i>
            </button>
        </a>
    
</nav>

        </div>
    </div>



                    
                        <!-- Overlay For Active Sidebar -->
<div class="sidebar-overlay"></div>

<!-- Material sidebar -->
<aside id="sidebar" class="sidebar sidebar-colored sidebar-fixed-left" role="navigation">
    <div id="sidebar-main">
        <!-- Sidebar Header -->
        <div class="sidebar-header header-cover" style="background-image: url(/img/sidebar_header.png);">
    <!-- Top bar -->
    <div class="top-bar"></div>

    <!-- Sidebar toggle button -->
    <button type="button" class="sidebar-toggle mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon" style="display: initial;" data-upgraded=",MaterialButton,MaterialRipple">
        <i class="material-icons">clear_all</i>
        <span class="mdl-button__ripple-container">
            <span class="mdl-ripple">
            </span>
        </span>
    </button>

    <!-- Sidebar Avatar -->
    <div class="sidebar-image">
        <img src="/img/avatar.png" alt="BirdZhang's avatar">
    </div>

    <!-- Sidebar Email -->
    <a data-toggle="dropdown" class="sidebar-brand" href="#settings-dropdown">
        0312birdzhang@email.com
        <b class="caret"></b>
    </a>
</div>


        <!-- Sidebar Navigation  -->
        <ul class="nav sidebar-nav">
    <!-- User dropdown  -->
    <li class="dropdown">
        <ul id="settings-dropdown" class="dropdown-menu">
            
                <li>
                    <a href="mailto:0312birdzhang@gmail.com" target="_blank" title="Email Me">
                        
                            <i class="material-icons sidebar-material-icons sidebar-indent-left1pc-element">email</i>
                        
                        Email Me
                    </a>
                </li>
            
        </ul>
    </li>

    <!-- Homepage -->
    
        <li id="sidebar-first-li">
            <a href="/" target="_self">
                
                    <i class="material-icons sidebar-material-icons">home</i>
                
                主页
            </a>
        </li>
        
    

    <!-- Archives  -->
    
        <li class="dropdown">
            <a href="#" class="ripple-effect dropdown-toggle" data-toggle="dropdown">
                
                    <i class="material-icons sidebar-material-icons">inbox</i>
                
                    归档
                <b class="caret"></b>
            </a>
            <ul class="dropdown-menu">
            <li>
                <a class="sidebar_archives-link" href="/archives/2019/07/">七月 2019<span class="sidebar_archives-count">1</span></a></li><li><a class="sidebar_archives-link" href="/archives/2019/06/">六月 2019<span class="sidebar_archives-count">1</span></a></li><li><a class="sidebar_archives-link" href="/archives/2019/05/">五月 2019<span class="sidebar_archives-count">1</span></a></li><li><a class="sidebar_archives-link" href="/archives/2019/04/">四月 2019<span class="sidebar_archives-count">1</span></a></li><li><a class="sidebar_archives-link" href="/archives/2018/12/">十二月 2018<span class="sidebar_archives-count">1</span></a></li><li><a class="sidebar_archives-link" href="/archives/2018/09/">九月 2018<span class="sidebar_archives-count">2</span></a></li><li><a class="sidebar_archives-link" href="/archives/2018/08/">八月 2018<span class="sidebar_archives-count">1</span></a></li><li><a class="sidebar_archives-link" href="/archives/2018/07/">七月 2018<span class="sidebar_archives-count">1</span></a></li><li><a class="sidebar_archives-link" href="/archives/2018/06/">六月 2018<span class="sidebar_archives-count">3</span></a></li><li><a class="sidebar_archives-link" href="/archives/2018/05/">五月 2018<span class="sidebar_archives-count">2</span></a></li><li><a class="sidebar_archives-link" href="/archives/2018/03/">三月 2018<span class="sidebar_archives-count">1</span></a></li><li><a class="sidebar_archives-link" href="/archives/2018/01/">一月 2018<span class="sidebar_archives-count">2</span></a></li><li><a class="sidebar_archives-link" href="/archives/2017/12/">十二月 2017<span class="sidebar_archives-count">3</span></a></li><li><a class="sidebar_archives-link" href="/archives/2017/08/">八月 2017<span class="sidebar_archives-count">1</span></a></li><li><a class="sidebar_archives-link" href="/archives/2017/06/">六月 2017<span class="sidebar_archives-count">1</span></a></li><li><a class="sidebar_archives-link" href="/archives/2017/05/">五月 2017<span class="sidebar_archives-count">8</span></a>
            </ul>
        </li>
        
    

    <!-- Categories  -->
    

    <!-- Pages  -->
    
        <li>
            <a href="/links/" title="友情链接">
                
                    <i class="material-icons sidebar-material-icons">link</i>
                
                友情链接
            </a>
        </li>
        
    
        <li>
            <a href="/about" title="关于我">
                
                    <i class="material-icons sidebar-material-icons">person</i>
                
                关于我
            </a>
        </li>
        
    
        <li>
            <a href="/tags" title="标签">
                
                    <i class="material-icons sidebar-material-icons">bookmark</i>
                
                标签
            </a>
        </li>
        
    

    <!-- Article Number  -->
    
</ul>


        <!-- Sidebar Footer -->
        <!--
I'm glad you use this theme, the development is no so easy, I hope you can keep the copyright, I will thank you so much.
If you still want to delete the copyrights, could you still retain the first one? Which namely "Theme Material"
It will not impact the appearance and can give developers a lot of support :)

很高兴您使用并喜欢该主题，开发不易 十分谢谢与希望您可以保留一下版权声明。
如果您仍然想删除的话 能否只保留第一项呢？即 "Theme Material"
它不会影响美观并可以给开发者很大的支持和动力。 :)
-->

<!-- Sidebar Divider -->

    <div class="sidebar-divider"></div>


<!-- Theme Material -->

    <a href="https://github.com/viosey/hexo-theme-material"  class="sidebar-footer-text-a" target="_blank">
        <div class="sidebar-text mdl-button mdl-js-button mdl-js-ripple-effect sidebar-footer-text-div" data-upgraded=",MaterialButton,MaterialRipple">
            主题 - Material
            <span class="sidebar-badge badge-circle">i</span>
        </div>
    </a>


<!-- Help & Support -->
<!--

-->

<!-- Feedback -->
<!--

-->

<!-- About Theme -->
<!--

-->

    </div>

    <!-- Sidebar Image -->
    

</aside>

                    

                    
                        <!-- Footer Top Button -->
                        <div class="toTop-wrap">
    <a href="#top" class="toTop">
        <i class="material-icons footer_top-i">expand_less</i>
    </a>
</div>

                    

                    <!--Footer-->
<footer class="mdl-mini-footer" id="bottom">
    
        <!-- Paradox Footer Left Section -->
        <div class="mdl-mini-footer--left-section sns-list">
    <!-- Twitter -->
    
        <a href="https://twitter.com/0312birdzhang" target="_blank">
            <button class="mdl-mini-footer--social-btn social-btn" style="background-image: url(/img/footer/footer_ico-twitter.png);">
                <span class="visuallyhidden">Twitter</span>
            </button><!--
     --></a>
    

    <!-- Facebook -->
    

    <!-- Google + -->
    
        <a href="https://www.google.com/0312birdzhang" target="_blank">
            <button class="mdl-mini-footer--social-btn social-btn" style="background-image: url(/img/footer/footer_ico-gplus.png);">
                <span class="visuallyhidden">Google Plus</span>
            </button><!--
     --></a>
    

    <!-- Weibo -->
    
        <a href="http://weibo.com/0312birdzhang" target="_blank">
            <button class="mdl-mini-footer--social-btn social-btn" style="background-image: url(/img/footer/footer_ico-weibo.png);">
                <span class="visuallyhidden">Weibo</span>
            </button><!--
     --></a>
    

    <!-- Instagram -->
    

    <!-- Tumblr -->
    

    <!-- Github -->
    
        <a href="https://github.com/0312birdzhang" target="_blank">
            <button class="mdl-mini-footer--social-btn social-btn" style="background-image: url(/img/footer/footer_ico-github.png);">
                <span class="visuallyhidden">Github</span>
            </button><!--
     --></a>
    

    <!-- LinkedIn -->
    

    <!-- Zhihu -->
    

    <!-- Bilibili -->
    

    <!-- Telegram -->
    
</div>


        <!--Copyright-->
        <div id="copyright">
            Copyright&nbsp;©&nbsp;
            <script type="text/javascript">
                var fd = new Date();
                document.write(fd.getFullYear());
            </script>
            &nbsp;BirdZhang's Blog
        </div>

        <!-- Paradox Footer Right Section -->

        <!--
        I am glad you use this theme, the development is no so easy, I hope you can keep the copyright.
        It will not impact the appearance and can give developers a lot of support :)

        很高兴您使用该主题，开发不易，希望您可以保留一下版权声明。
        它不会影响美观并可以给开发者很大的支持。 :)
        -->

        <div class="mdl-mini-footer--right-section">
            <div>
                <div class="footer-develop-div">Powered by <a href="https://hexo.io" target="_blank" class="footer-develop-a">Hexo</a></div>
                <div class="footer-develop-div">Theme - <a href="https://github.com/viosey/hexo-theme-material" target="_blank" class="footer-develop-a">Material</a></div>
            </div>
        </div>
    
</footer>


                    <!-- Import File -->
<script src="/js/lazyload.min.js"></script>
<script src="/js/js.min.js"></script>
<script src="/js/nprogress.js"></script>

<script type="text/javascript">
    NProgress.configure({
        showSpinner: true
    });
    NProgress.start();
    $('#nprogress .bar').css({
        'background': '#29d'
    });
    $('#nprogress .peg').css({
        'box-shadow': '0 0 10px #29d, 0 0 15px #29d'
    });
    $('#nprogress .spinner-icon').css({
        'border-top-color': '#29d',
        'border-left-color': '#29d'
    });
    setTimeout(function() {
        NProgress.done();
        $('.fade').removeClass('out');
    }, 800);
</script>





    <!-- Leancloud -->
    <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
    <script>
        AV.initialize('MguK71QUSGyrb4biWtu5oPqN-gzGzoHsz', 'ghPhHxzVQtKRfKt72twwiUFx');
    </script>
    <script>
    function showTime(Counter) {
        var query = new AV.Query(Counter);
        $('.leancloud-views_num').each(function() {
            var url = $(this).attr('id').trim();
            query.equalTo('url', url);
            query.find({
                success: function(results) {
                    if (results.length === 0) {
                        var content = '0 ' + $(document.getElementById(url)).text();
                        $(document.getElementById(url)).text(content);
                        return;
                    }
                    for (var i = 0; i < results.length; i++) {
                        var object = results[i];
                        var content = object.get('time') + ' ' + $(document.getElementById(url)).text();
                        $(document.getElementById(url)).text(content);
                    }
                },
                error: function(object, error) {
                    console.log('Error: ' + error.code + ' ' + error.message);
                }
            });
        });
    }

    function addCount(Counter) {
      var Counter = AV.Object.extend('Counter');
      url = $('.leancloud-views_num').attr('id').trim();
      title = $('.leancloud-views_num').attr('data-flag-title').trim();
      var query = new AV.Query(Counter);
      query.equalTo('url', url);
      query.find({
          success: function(results) {
            if (results.length > 0) {
                var counter = results[0];
                counter.fetchWhenSave(true);
                counter.increment('time');
                counter.save(null, {
                    success: function(counter) {
                        var content =  counter.get('time') + ' ' + $(document.getElementById(url)).text();
                        $(document.getElementById(url)).text(content);
                    },
                    error: function(counter, error) {
                        console.log('Failed to save Visitor num, with error message: ' + error.message);
                    }
                });
            } else {
              var newcounter = new Counter();
              newcounter.set('title', title);
              newcounter.set('url', url);
              newcounter.set('time', 1);
              newcounter.save(null, {
                  success: function(newcounter) {
                      console.log('newcounter.get(\'time\')='+newcounter.get('time'));
                      var content = newcounter.get('time') + ' ' + $(document.getElementById(url)).text();
                      $(document.getElementById(url)).text(content);
                  },
                  error: function(newcounter, error) {
                      console.log('Failed to create');
                  }
              });
            }
        },
        error: function(error) {
            console.log('Error:' + error.code + ' ' + error.message);
        }
      });
    }
    $(function() {
        var Counter = AV.Object.extend('Counter');
        if ($('.leancloud-views_num').length === 1) {
            addCount(Counter);
        } else if ($('.post-title-link').length > 1) {
            showTime(Counter);
        }
    });
</script>








    <!-- 使用 DISQUS js 代码 -->
    <script id="dsq-count-scr" src="//0312birdzhang-github-io.disqus.com/count.js" async></script>



<!-- Swiftye -->


<!-- Local Search-->


<!-- Window Load-->
<script>
    $(window).load(function() {
        // Post_Toc parent position fixed
        $('.post-toc-wrap').parent('.mdl-menu__container').css('position', 'fixed');
    });
</script>

<!-- MathJax Load-->


                </main>
            </div>
        </body>
    
</html>
